package com.inteligenciaartificial;

public class Node {

    public  int depth;
    public  String State;
    public  int Cost;
    public  Node Parent;
    public  float G;
    public  float MD; //Misplaced tiles or Manhattan Distance
    public 	float F;
	private String final_state = "1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-0-";

    
    // Parent Node  which has depth =0 and parent = null;
    public Node (String State)
    {
        this.State = State;
        this.Parent = null;
        this.depth = 0;
        
        
        
        
        
        
    }

    // this form of Generalization of Node Constructor which accepts 
    // any node root or ordinary node;

    public Node(String state_zero,Node Parent)
    {
        this.State = state_zero;
        this.Parent = Parent;
        if (Parent == null)
            this.depth = 0;
        else
            this.depth = Parent.depth + 1;  
        
    }
    
    // this form of Generalization of Node Constructor which accepts 
    // any node root or ordinary node;

    public Node(String state_zero,Node Parent, float MD)
    {
    	String[] arrayStates = state_zero.split("-");
    	String[] arrayGoalStates = final_state.split("-");
    	int sum = 0;
    	for(int i = 0; i < arrayStates.length; i++){
    		if(! arrayStates[i].equals(arrayGoalStates[i])){
    			sum++;
    		}
    	}
    	
        this.State = state_zero;
        this.Parent = Parent;
        if (Parent == null)
            this.depth = 0;
        else
            this.depth = Parent.depth + 1; 
        this.MD = sum;
        this.F = depth + this.MD;
    }
	
	
}
